import React, { useEffect, useState } from 'react';
import { Link } from 'react-router';

export default function Example() {
 
  const [title, setTitle] = useState("hello world");
  const [count, setCount] = useState(0);

  const update=()=>{

    setTitle("您好 世界");
    //console.log(title);

  }

  useEffect(()=>{
    //console.log("useEffect");

    console.log(title);
    
  },[title])

  useEffect(()=>{
   
    console.log("页面更新");
    
  })

  let interval= setInterval(()=>{

    console.log(new Date());
    
  },1000)


  useEffect(()=>{
   
    console.log("页面挂载完成");
    return ()=>{
        console.log("组件销毁");
        clearInterval(interval);
    }
    
  },[])

 
  return (
    <div>
       <div>{count}</div>
      <p>{title}</p>
      <button onClick={update}>
        Click me
      </button>

      <button onClick={()=>setCount(count+1)}>
      ++
      </button>

      <Link to={'/'}>首页</Link>
    </div>
  );
}